package com.xuyiwei.mayi.test;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * Created by xuyiwei on 2019/4/13.
 */
public class CalibProxy implements MethodInterceptor {
    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        System.out.println("cglib代理开始");
        Object ob =  methodProxy.invokeSuper(o,objects);
        System.out.println("cglib代理结束");
        return ob;
    }

    public static void main(String[] args) {
        CalibProxy calibProxy = new CalibProxy();
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(HoseImpl.class);
        enhancer.setCallback(calibProxy);
        HoseImpl imp = (HoseImpl) enhancer.create();
        imp.mai();
    }
}
